﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.Area;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LJX.SmartPark.Service.Area.Dto;

namespace LJX.SmartPark.Service.Area.SchedulSer
{
    public class ScheduleServerice : IScheduleServerice
    {
        //注入
        private readonly IRepository<Schedule> _repository;

        public ScheduleServerice(IRepository<Schedule> studentService)
        {
            _repository = studentService;
        }

        /// <summary>
        /// 显示分页查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<Response<List<Schedule>>> GetScheduleServerice(model input)
        {
            var obj = _repository.GetListQuery();
            obj = obj.WhereIf(!string.IsNullOrWhiteSpace(input.quyu), x => x.Area.Contains(input.quyu));
            obj = obj.WhereIf(!string.IsNullOrWhiteSpace(input.name), x => x.Person.Contains(input.name));
            var totalCount = obj.Count();
            obj = obj.Skip(((input.pageIndex - 1) * input.pageSize)).Take(input.pageSize);
            var result = obj.MapToList<Schedule>();
            return Response<List<Schedule>>.Ok(result, totalCount);
        }
    }
}
